<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>检测浏览器对WebSocket是否支持</title>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
function Log(Text, MessageType) {
            if (MessageType == "OK") 
            {
            Text = "<span style='color: green;'>" + Text + "</span>";//连接已建立
            }
            if (MessageType == "ERROR") 
            {
            Text = "<span style='color: red;'>" + Text + "</span>";//远程连接中断
            }
            document.getElementById("support").innerHTML = document.getElementById("support").innerHTML + Text + "<br />";
        };

$(document).ready(function () {
            alert("哈哈,我执行了!");
            var WebSocketsExist = true;//WebSocketsExist存在
            try {
                var ws = new WebSocket("ws://127.0.0.1:5200");
				ws.onopen = function(evt) {  //绑定连接事件
　　console.log("Connection open ..."); 
　　ws.send("发送的数据");
};

ws.onmessage = function(evt) {//绑定收到消息事件
　　console.log( "Received Message: " + evt.data);
};

ws.onclose = function(evt) { //绑定关闭或断开连接事件
　　console.log("Connection closed.");
};
            } 
            catch (ex) {
                try
                {
                  webSocket = new MozWebSocket("ws://127.0.0.1:5200");
                }
                catch(ex)
                {
                  WebSocketsExist = false;
                }
            }
			console.log(ws);
            if (WebSocketsExist) {
                Log("您的浏览器支持WebSocket. 您可以尝试连接到聊天服务器!", "OK");

            } else {
                Log("您的浏览器不支持WebSocket。请选择其他的浏览器再尝试连接服务器。", "ERROR");
            }   
     });
    
</script>
</head>
<body>
     <div id='support' ></div>
</body>
</html>